using System;
using System.Text;
using System.Data;

namespace TimeSheetBLL.Brokers
{
	/// <summary>
	/// A nice description of UserBroker goes here.
	/// 
	/// Version: $Id: UserBroker.cs,v 1.1 2004/03/08 23:57:02 jperrin Exp $
	/// 
	/// Date: 
	/// Copyright: 2004, Kanga Communications, Calgary, Alberta, Canada. 
	/// </summary>
	public class UserBroker : Broker
	{
		#region Private



		#endregion

		public UserBroker() : base()
		{
			
		}

		#region Methods

		public override bool Delete( IDBEntity entity )
		{
			User user = (User)entity;
			user.Active = false;

			return data.ExecuteNonQuery( tools.DBUpdateQuery( user ) ) > 0;
		}

		public override DataTable SelectAll( IDBEntity entity )
		{
			StringBuilder sb = new StringBuilder();
			sb.Append( "SELECT  user_id, user_name, password, email, first_name, " );
			sb.Append( "last_name, date_created, active, concat(first_name, ' ', last_name) AS full_name " );
			sb.Append( "FROM users WHERE active = 1 ORDER BY last_name " );
			
			return this.data.GetTable( sb.ToString() );
		}

		#endregion

		#region Properties



		#endregion
	}
}
